package org.black.phoneUtility.app.fragment;

import org.black.phoneUtility.R;
import org.black.phoneUtility.app.activity.BackupActivity;
import org.black.phoneUtility.app.activity.RestoreActivity;
import org.black.phoneUtility.util.admob.AdmobConstant;

import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.AdSize;
import com.google.android.gms.ads.AdView;

import android.app.Fragment;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.LinearLayout;

public class BackupAndRestoreFragment extends Fragment implements
		View.OnClickListener {
	public static final String TAG = BackupAndRestoreFragment.class.getName();
	private static final String LOG_TAG = BackupAndRestoreFragment.class
			.getName();

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		getActivity().setTitle(
				getString(R.string.phone_utility_backup_and_restore_title));
		View result = inflater.inflate(
				R.layout.phone_utility_backup_and_restore, container, false);
		Button backupButton = (Button) result
				.findViewById(R.id.phoneUtilityBackupRestoreBackupButton);
		backupButton.setOnClickListener(this);
		Button restoreButton = (Button) result
				.findViewById(R.id.phoneUtilityBackupRestoreRestoreButton);
		restoreButton.setOnClickListener(this);
		Button deleteBackupButton = (Button) result
				.findViewById(R.id.phoneUtilityBackupRestoreDeleteBackupsButton);
		deleteBackupButton.setOnClickListener(this);

		AdView adView = new AdView(getActivity());
		adView.setAdSize(AdSize.SMART_BANNER);
		adView.setAdUnitId(AdmobConstant.UNIT_ID);
		AdRequest adRequest = new AdRequest.Builder().build();
		LinearLayout adViewLayout = (LinearLayout) result
				.findViewById(R.id.adViewLayout);
		adViewLayout.addView(adView);
		adView.loadAd(adRequest);

		Log.i(LOG_TAG, "Create View");
		return result;
	}

	@Override
	public void onDestroyView() {
		super.onDestroyView();
		Log.i(LOG_TAG, "Destory View");
	}

	@Override
	public void onClick(View v) {
		if (v.getId() == R.id.phoneUtilityBackupRestoreBackupButton) {
			Intent intent = new Intent(getActivity(), BackupActivity.class);
			Bundle bundle = new Bundle();
			intent.putExtras(bundle);
			startActivity(intent);
			getActivity().overridePendingTransition(
					R.animator.right_slide_enter, R.animator.right_slide_exit);
		} else if (v.getId() == R.id.phoneUtilityBackupRestoreRestoreButton) {
			Intent intent = new Intent(getActivity(), RestoreActivity.class);
			Bundle bundle = new Bundle();
			intent.putExtras(bundle);
			startActivity(intent);
			getActivity().overridePendingTransition(
					R.animator.right_slide_enter, R.animator.right_slide_exit);
		} else {

		}
	}

}
